package com.ruoyi.marketing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.marketing.domain.Marketing;
import com.ruoyi.marketing.service.IMarketingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品营销Controller
 * 
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/marketing/marketing")
public class MarketingController extends BaseController
{
    @Autowired
    private IMarketingService marketingService;

    /**
     * 查询商品营销列表
     */
//    @PreAuthorize("@ss.hasPermi('marketing:marketing:list')")
    @GetMapping("/list")
    public TableDataInfo list(Marketing marketing)
    {
        startPage();
        List<Marketing> list = marketingService.selectMarketingList(marketing);
        return getDataTable(list);
    }

    /**
     * 导出商品营销列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:marketing:export')")
    @Log(title = "商品营销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Marketing marketing)
    {
        List<Marketing> list = marketingService.selectMarketingList(marketing);
        ExcelUtil<Marketing> util = new ExcelUtil<Marketing>(Marketing.class);
        util.exportExcel(response, list, "商品营销数据");
    }

    /**
     * 获取商品营销详细信息
     */
//    @PreAuthorize("@ss.hasPermi('marketing:marketing:query')")
    @GetMapping(value = "/{methodsId}")
    public AjaxResult getInfo(@PathVariable("methodsId") Long methodsId)
    {
        return success(marketingService.selectMarketingByMethodsId(methodsId));
    }

    /**
     * 新增商品营销
     */
    @PreAuthorize("@ss.hasPermi('marketing:marketing:add')")
    @Log(title = "商品营销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Marketing marketing)
    {
        return toAjax(marketingService.insertMarketing(marketing));
    }

    /**
     * 修改商品营销
     */
    @PreAuthorize("@ss.hasPermi('marketing:marketing:edit')")
    @Log(title = "商品营销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Marketing marketing)
    {
        return toAjax(marketingService.updateMarketing(marketing));
    }

    /**
     * 删除商品营销
     */
    @PreAuthorize("@ss.hasPermi('marketing:marketing:remove')")
    @Log(title = "商品营销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{methodsIds}")
    public AjaxResult remove(@PathVariable Long[] methodsIds)
    {
        return toAjax(marketingService.deleteMarketingByMethodsIds(methodsIds));
    }
}
